package me.shurufa.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.shurufa.R;
import me.shurufa.activities.SelectDigestBookActivity;
import me.shurufa.model.NewDigest;
import me.shurufa.model.AddDigestBean;
import me.shurufa.utils.Constants;

/**
 * 作者 : andy
 * 日期 : 16/3/9 10:31
 * 邮箱 : andyxialm@gmail.com
 * 描述 : 内容简介 Fragment
 */
public class BookDigestModifyFragment extends BaseFragment implements View.OnClickListener {

    @Bind(R.id.btn_select_digestbook)
    TextView mSelectDigestBookBtn;

    @Bind(R.id.et_page_num)
    EditText et_page_num;

    @Bind(R.id.et_note)
    EditText et_note;

    @Bind(R.id.et_digest)
    EditText et_digest;

    @Bind(R.id.cb_save_not_send)
    CheckBox cb_save_not_send;

    @Bind(R.id.tv_save_send)
    TextView tv_save_send;

    private NewDigest mDigest;

    public static BookDigestModifyFragment create(NewDigest digest) {
        BookDigestModifyFragment fragment = new BookDigestModifyFragment();
        Bundle args = new Bundle();
        args.putSerializable(Constants.ARG_MODIFY_DIGEST, digest);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mDigest = (NewDigest) getArguments().getSerializable(Constants.ARG_MODIFY_DIGEST);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_digest_add_note, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    protected void initUI(View view) {
        super.initUI(view);
        initData();
        initListener();
    }

    private void initListener() {
        mSelectDigestBookBtn.setOnClickListener(this);
        tv_save_send.setOnClickListener(this);
    }

    private void initData() {
        et_digest.setText(mDigest.getContent());
        et_digest.requestFocus();

        et_note.setText(mDigest.getNote());
        et_page_num.setText(mDigest.getPage_num());
        // mSelectDigestBookBtn.setText(mDigest.);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.right_text:
                onNext();
                break;
            case R.id.btn_select_digestbook:
                Intent in = new Intent(getActivity(), SelectDigestBookActivity.class);
                // SelectDigestBookActivity.initArguments(in, mAddDigestBean);
                startActivity(in);
                break;
            case R.id.tv_save_send:
                cb_save_not_send.toggle();
                break;
        }
    }

    // 右上角点击下一步
    private void onNext() {

    }

    /**
     * 选择书摘本
     * @param intent
     */
    public void onEventMainThread(Intent intent) {
        if (intent.getAction().equals(Constants.EVENT_SELECT_DIGEST_BOOK)){
        }
    }

    public AddDigestBean getAddDigestBean() {
        return null;
    }


}
